package com.tjvib.adapter;

import android.widget.CheckBox;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.tjvib.R;
import com.tjvib.bean.BLEDevice;
import com.tjvib.bean.SensorInfo;
import com.tjvib.util.ToastUtil;
import com.tjvib.widget.ListItemOnClickListener;

import java.util.List;

public class DeviceAdapter extends BaseQuickAdapter<SensorInfo, BaseViewHolder> {
    private ListItemOnClickListener itemOnClickListener;

    public DeviceAdapter(int layoutResId, @Nullable List<SensorInfo> data, ListItemOnClickListener itemOnClickListener) {
        super(layoutResId, data);
        this.itemOnClickListener = itemOnClickListener;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, SensorInfo sensorInfo) {
        baseViewHolder.setText(R.id.item_device_tv_name, sensorInfo.getName())
                .setText(R.id.item_device_tv_ip, sensorInfo.getAddress());

        CheckBox cb = baseViewHolder.findView(R.id.item_device_cb_choose);
        if (sensorInfo.getStatus().equals("connected"))
            cb.setChecked(true);
        else
            cb.setChecked(false);

        cb.setOnClickListener(v -> {
            itemOnClickListener.onClick(v, sensorInfo);
        });
    }
}
